import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' 
import vueJsx from '@vitejs/plugin-vue-jsx'
import WindiCSS from 'vite-plugin-windicss';
import DefineOptions from 'unplugin-vue-define-options/vite';
function pathResolve(dir) {
  return path.resolve(process.cwd(), '.', dir);
}
export default defineConfig({
  resolve: {
    alias: {
      '@': pathResolve('src') + '/',
      '@views': pathResolve('./src/views') + '/',
    }
  }, 
  plugins: [
    
   
    vue(),
    vueJsx(),
    // 组件名
    DefineOptions(),
    // 按需引入
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
       // 配置CDN
    // PluginImportToCDN.default({
    //     modules: [
    //         {
    //             name: 'vue',
    //             var: 'Vue',
    //             path: 'https://unpkg.com/vue@next',
    //         },
    //         {
    //             name: 'element-plus',
    //             var: 'ElementPlus',
    //             path: `https://unpkg.com/element-plus`,
    //             css: 'https://unpkg.com/element-plus/dist/index.css',
    //         },
    //     ],
    // }),
    // css源配置
    WindiCSS(),
  ],
  css: {
     
    preprocessorOptions: { 
        scss: {
         
        },
        //消除element-plus警告
        postcss: {
            plugins: [ 
                {
                    postcssPlugin: 'internal:charset-removal',
                    AtRule: {
                        charset: atRule => {
                            if (atRule.name === 'charset') {
                                atRule.remove()
                            }
                        },
                    },
                },
            ],
        },
    },
},
build: {
    cssCodeSplit: true,  // 单独抽离css
    terserOptions: {
        compress: {
            //生产环境时移除console
            drop_console: true,
            drop_debugger: true,
        },
    },
    // 取消计算文件大小，加快打包速度
    reportCompressedSize: false,
    sourcemap: true,
    // assetsDir: 'static/img',
    rollupOptions: {
        output: {
            chunkFileNames: 'js/[name]-[hash].js',
            entryFileNames: 'js/[name]-[hash].js',
            assetFileNames: '[ext]/[name]-[hash].[ext]',
        },
    },
},
})
